package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.StockOutcomeBill;
import cn.wolfcode.crm.query.JSONResult;
import cn.wolfcode.crm.query.PageResult;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IDepotService;
import cn.wolfcode.crm.service.IStockOutcomeBillService;
import cn.wolfcode.crm.service.ISupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@RequestMapping("stockOutcomeBill")
public class StockOutcomeBillController {

    @Autowired
    private IStockOutcomeBillService stockOutcomeBillService;

    //由于dataGrid组件返回必须为json,所以跳转界面就分开
    @RequestMapping("view")
    public String view(){
        return "stockOutcomeBill";
    }

    //退货编辑界面需要
    @RequestMapping("list")
    @ResponseBody
    public List<StockOutcomeBill> list() throws Exception{
        return stockOutcomeBillService.selectAll();
    }

    //页面数据
    @RequestMapping("query")
    @ResponseBody
    public PageResult query(QueryObject qo){
        return stockOutcomeBillService.query(qo);
    }


    //编辑
    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public JSONResult saveOrUpdate(StockOutcomeBill s){
        stockOutcomeBillService.saveOrUPdate(s);
        return new JSONResult();
    }

    //删除
    @RequestMapping("delete")
    @ResponseBody
    public JSONResult delete(Long id){
        JSONResult result = new JSONResult();
        try{
            stockOutcomeBillService.deleteByPrimaryKey(id);
        }catch (Exception e){
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }

    @RequestMapping("audit")
    @ResponseBody
    public Object audit(Long id) throws Exception{
        JSONResult result = new JSONResult();
        try {
            stockOutcomeBillService.audit(id);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }
}
